import torch
import numpy as np


# 1. 使用from_numpy方法, 可以将ndarray数组转换为Tensor
# 2. torch.tensor 可以将ndarray 数组转换为Tensor

# 将numpy数组转换为张量类型
data_numpy = np.array([2, 3, 4])
data_tensor = torch.from_numpy(data_numpy)
print(data_tensor)
print(type(data_tensor))
print(data_tensor.dtype)
print(data_numpy)
print('#######################################')
data_numpy = np.array([[1, 2, 3], [4, 5, 6]])
data_tensor = torch.tensor(data_numpy)
print(data_tensor)
print(type(data_tensor))
print(data_tensor.dtype)
